{include file="base/header"} 
<div class="layui-card">
            <div class="layui-card-body">
                <form class="layui-form" action="javascript:;">
                    <div class="layui-form-item">
                        <div class="layui-form-item layui-inline">
                            <label class="layui-form-label">标题</label>
                            <div class="layui-input-inline">
                                <input type="text" name="title" placeholder="标题" class="layui-input">
                            </div>
                        </div>
              
                      
                        <div class="layui-form-item layui-inline">
                            <label class="layui-form-label">状态</label>
                            <div class="layui-input-inline">
                                <select name="status">
                                <option value="">-请选择-</option>
                                <option value="1">上架</option>
                                <option value="2">下架</option>
                        </select>
                            </div>
                        </div>
                        
                        <div class="layui-form-item layui-inline">
                            <button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="user-query">
                                <i class="layui-icon layui-icon-search"></i>
                                查询
                            </button>
                            <button type="reset" class="pear-btn pear-btn-md">
                                <i class="layui-icon layui-icon-refresh"></i>
                                重置
                            </button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
        <style>
            td .laytable-cell-1-0-0{
                color:red;
                cursor: pointer;
            }
        </style>
        <div class="layui-card">
            <div class="layui-card-body">
                <table id="tableId" lay-filter="user-table"></table>
            </div>
        </div>
        {php} $typeLt=empty($_GET['type']) ? 0 : $_GET['type']; $arrsSN=["","",""]; $Tcn=$arrsSN[$typeLt]; {/php}
        <script type="text/html" id="user-toolbar">
            <button class="pear-btn pear-btn-primary pear-btn-md" lay-event="add">
                <i class="layui-icon layui-icon-add-1"></i>
                新增{$Tcn}
            </button>
        </script>
        <script type="text/html" id="tpl-goods">
            <div >
                {if $typeLt!=2}
                    {if $typeLt==0}
                        <img src="/static/files/runtimefile/{{d.img}}" class="layui-nav-img" style="width: 70px;border-radius: 2px;">
                    {else/} 
                        <img src="/static/files/runtimefile/{{d.img}}" class="layui-nav-img" style="height: 30px;border-radius: 2px;">
                    {/if}
                {/if}
                <span style="color: #936835;">{{d.title}}</span>
                <!-- lay-event="editTitle" -->
            </div>
        </script>
        <script type="text/html" id="tpl-auser">
            {{#if (d.amsg ) { }}
                <img src="/static/efile/auserimg/{{d.amsg.img}}" class="layui-nav-img">
                <span>{{d.amsg.nickname}}
                </span>
                {{#if (d.amsg.mobile ) { }}
                    <span>| {{d.amsg.mobile}}</span>
                {{# } }}
            {{# } }}
        </script>

   

      
        <script type="text/html" id="goods-status">
            	<input type="checkbox" name="status" value="{{d.id}}" lay-skin="switch" lay-text="上架|下架" lay-filter="user-status-set" {{ d.status ? 'checked' : '' }} />
        </script>
        <script type="text/html" id="goods-set">
            <button class="pear-btn pear-btn-primary pear-btn-xs" lay-event="edit">编辑</button>
        	<button class="pear-btn pear-btn-danger pear-btn-xs" lay-event="delete">删除</button>
        </script>
        <script>
			layui.use(['table', 'form', 'jquery','common', 'tab'], function() {
                
            

				let table = layui.table;
				let form = layui.form;
                var tab = layui.tab;
				let $ = layui.jquery;
				let common = layui.common;
                let cols = [
                    [{
                        title: '权重',
                        field: 'or_w',
                        align: 'center', 
                        edit:true,
                        width: 50,
                        event:"orFun"
                    },{
                        title: 'ID',
                        field: 'id',
                        align: 'center',
                        width: 50,
                    },
                    {
                            title: '标题',
                            field: 'img',
                            align: 'left',
                            templet: '#tpl-goods'
                        },
                    {
                        title: '状态',
                        field: 'status',
                        align: 'center',
                        templet: '#goods-status',
                        width: 160,
                    },
                    {
                        title: '创建时间',
                        field: 'addtime',
                        align: 'left',
                        width: 200,
                    },
                    {
                        title: '创建人',
                        templet: '#tpl-auser',
                        align: 'left',
                        width: 200,
                    },
                    {
                        title: '操作',
                        toolbar: '#goods-set',
                        align: 'left',
                        width: 300,
                    }
                    ]
                ];
                table.render({
                    elem: '#tableId',
                    url: "{:url('article/artlst')}?type={$typeLt}",
                    page: true,
                    cols: cols,
                    skin: 'line',
                    toolbar: '#user-toolbar',
                    defaultToolbar: [{
                        title: '刷新',
                        layEvent: 'refresh',
                        icon: 'layui-icon-refresh',
                    }, 'filter',  'exports']
                });
                form.on('switch(user-status-set)', function (obj) {
                    console.log(obj);
                    var id= this.value;
                    var status= obj.elem.checked ? 1 :0 ;
                    var str= status ? "已上架" : "已下架";
                    postData("{:url('article/setStatus')}",{ id,status }).then(function(res){
                        if(res.code!=200){
                            layer.alert(res.message,{title:"提示"});
                            return;
                        }
                        layer.tips(str, obj.othis);
                    });

                });
                table.on('tool(user-table)', function (obj) {
                    var data=obj.data;
                    if (obj.event === 'edit') {
                        layer.open({
                            type: 2,
                            title: '修改{$Tcn}->'+ data.title,
                            shade: 0.1,
                            area: ['1100px', '800px'],
                            content: "{:url('article/artedit')}?id="+data.id+"&type={$typeLt}"
                        });
                    }
                    if (obj.event === 'delete') {
                     
                        window.delete(obj);
                    }
                    if(obj.event==='orFun'){

                    }
                  
                   
                });
                listenTableEdit("user-table", "or_w");
                              //监听表格edit事件
                function listenTableEdit(tableElem, type) {
                    table.on('edit(' + tableElem + ')', function (obj) {
                        var dataLine = obj.data //得到所在行所有键值
                            , field = obj.field //得到字段
                            , value = obj.value; //得到修改后的值
                        let data = {id: dataLine.id};
                        data[field] = value;
                      
                        if(type=="or_w" && value>999){
                            msg1(1,"权重值不能大于999");
                            table.reload('tableId');
                            return;
                        }
                        data.table='article';
                        postData("{:url('base/orwEdit')}",data).then(function(res){
                            if(res.code==200){
                                
                                return;
                            }
                            layer.msg(res.message, {
                                icon: 2,
                                time: 1000
                            });
                        });

                    });
                }
                
                


                table.on('toolbar(user-table)', function (obj) {
                    if (obj.event === 'add') {
                        layer.open({
                            type: 2,
                            title: '新增{$Tcn}',
                            shade: 0.1,
                            area: ['1100px', '800px'],
                            content: "{:url('article/artedit')}?id=0&type={$typeLt}"
                        });
					}
                });
               
                window.refresh = function(param) {
					table.reload('tableId');
				}

               




          
                window.delete = function (obj) {
                    var id=obj.data.id;
                    layer.confirm('确定要删除该{$Tcn}->'+obj.data.title, {
                        icon: 3,
                        title: '提示'
                    }, function (index) {
                        layer.close(index);
                        loading=layer.load();
                        postData("{:url('article/itemDelete')}",{id:obj.data.id}).then(function(res){
                           layer.close(loading);
                     
                            if(res.code==200){
                                layer.msg(res.message, {
                                    icon: 1,
                                    time: 1000
                                }, function () {
                                    obj.del();
                                });
                                return;
                            }
                            layer.msg(res.message, {
                                icon: 2,
                                time: 1000
                            });
                        });
                    });
                    
                }
   

                form.on('submit(user-query)', function (data) {
                    table.reload('tableId', {
                        page: {curr: 1 },
                        where: data.field
                    })
                    return false;
                });

			})
		</script>
{include file="base/footer"}